package com.example.rdcproject.ving.notes.entity;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

//定义管理员类
public class Admin {
    private String account="admin";
    private List<User> users;        //管理用户集合
    private List<WordBook> wordbooks;//管理词书
    private AnnouncementBoard announcementboard;
    private String password="123456";

    public Admin() {
        users = new ArrayList<User>();
        wordbooks = new ArrayList<WordBook>();
        announcementboard = new AnnouncementBoard();

    }

    //新增用户
    public void addUser(User user) {
        users.add(user);
    }

    //删除用户
    public void deleteUser(String username) {
        for (int i = 0; i < users.size(); i++) {
            if (users.get(i).getNickname().equals(username)) {
                users.remove(i);
                break;
            }
        }
    }

    //查找用户
    public User findUser(String username) {
        for (User u : users) {
            if (u.getNickname().equals(username)) {
                return u;
            }
        }
        return null;
    }

    //列出所有用户信息
    public void listAllUsers() {
        for (User u : users) {
            System.out.println("用户的名称："+u.getNickname()+"用户的密码："+u.getPassword()+"用户的生日："
                    +u.getBirthdate()+"\n"+"用户的总学习天数："+u.getTotalStudyTime()+"用户连续学习的天数"+u.getContinuousDays());
        }
    }

    //新增单词书
    public void addWordBook(WordBook wordbook) {
        wordbooks.add(wordbook);
    }

    //删除单词书
    public void deleteWordBook(String name) {
        for (int i = 0; i < wordbooks.size(); i++) {
            if (wordbooks.get(i).getName().equals(name)) {
                wordbooks.remove(i);
                break;
            }
        }
    }

    //列出所有单词书
    public void listAllWordBooks() {
        for (WordBook wb : wordbooks) {
            System.out.println(wb.getName());
        }
    }

    //列出所有公告
    public void listAllAnnouncement() {
       announcementboard.getAnnouncements();
    }

    // 发布公告
    public void postAnnouncement(int id, String title,String content, LocalDateTime publishTime) {
        Announcement announcement = new Announcement(id, title,content, publishTime);
        announcementboard.addAnnouncement(announcement);
        System.out.println(announcement.getContent()+announcement.getPublishTime());
    }

    // 编辑公告
    public void editAnnouncement(int id, String newContent) {
         announcementboard.modifyAnnouncement(id, newContent);
    }

    // 删除公告
    public void deleteAnnouncement(int id) {
        announcementboard.removeAnnouncement(id);
    }

    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    public List<WordBook> getWordbooks() {
        return wordbooks;
    }

    public void setWordbooks(List<WordBook> wordbooks) {
        this.wordbooks = wordbooks;
    }

    public AnnouncementBoard getAnnouncementboard() {
        return announcementboard;
    }

    public void setAnnouncementboard(AnnouncementBoard announcementboard) {
        this.announcementboard = announcementboard;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
